//
//  NoContentView.m
//  Credit
//
//  Created by WangZhenyu on 16/4/12.
//  Copyright © 2016年 WangZhenyu. All rights reserved.
//

#import "NoContentView.h"
#import "GlobalFunction.h"

@interface NoContentView()

@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UIButton *actionBtn;

@property (copy, nonatomic) void (^ActionHandle)() ;

@end

@implementation NoContentView

- (id)initItemFrame:(CGRect)rect imageType:(InfoImageType)type title:(NSString *)title{
    self = [[[NSBundle mainBundle] loadNibNamed:@"NoContentView" owner:self options:nil] lastObject];
    if (self) {
        [self setFrame:rect];
        switch (type) {
            case InfoImageType_Default:
                self.imageView.image = [UIImage imageNamed:@"qiangdanren_kong_icon"];
                break;
            case InfoImageType_NoNetWork:
                self.imageView.image = [UIImage imageNamed:@"meiyouwang_icon"];
                break;
            case InfoImageType_NoList:
                self.imageView.image = [UIImage imageNamed:@"wode_shuaidan_kong_icon"];
                break;
            case InfoImageType_ServerFial:
                self.imageView.image = [UIImage imageNamed:@"serverfail"];
                break;
            default:
                break;
        }
        self.titleLabel.text = title;
        [self.actionBtn removeFromSuperview];
    }
    return self;
}

- (id)initItemFrame:(CGRect)rect imageName:(NSString *)imageStr title:(NSString *)title{
    self = [[[NSBundle mainBundle] loadNibNamed:@"NoContentView" owner:self options:nil] lastObject];
    if (self) {
        [self setFrame:rect];
        self.imageView.image = [UIImage imageNamed:imageStr];
        self.titleLabel.text = title;
        [self.actionBtn removeFromSuperview];
    }
    return self;
}

- (id)initItemFrame:(CGRect)rect imageType:(InfoImageType)type title:(NSString *)title btnTitle:(NSString *)btnTitle btnAction:(void (^)())handle{
    self = [[[NSBundle mainBundle] loadNibNamed:@"NoContentView" owner:self options:nil] lastObject];
    if (self) {
        [self setFrame:rect];
        switch (type) {
            case InfoImageType_Default:
                self.imageView.image = [UIImage imageNamed:@"qiangdanren_kong_icon"];
                break;
            case InfoImageType_NoNetWork:
                self.imageView.image = [UIImage imageNamed:@"meiyouwang_icon"];
                break;
            case InfoImageType_NoList:
                self.imageView.image = [UIImage imageNamed:@"wode_shuaidan_kong_icon"];
                break;
            case InfoImageType_ServerFial:
                self.imageView.image = [UIImage imageNamed:@"serverfail"];
                break;
            default:
                break;
        }
        self.titleLabel.text = title;
        [self.actionBtn setBackgroundImage:getColorToImage(ThemeColor) forState:UIControlStateNormal];
        [self.actionBtn setTitle:btnTitle forState:UIControlStateNormal];
        [self.actionBtn addTarget:self action:@selector(actionPress) forControlEvents:UIControlEventTouchUpInside];
        self.ActionHandle = handle;
    }
    return self;
}

- (void)actionPress{
    if (self.ActionHandle) {
        self.ActionHandle();
    }
}
@end
